#include "Camera.h"

Camera::Camera()
{
	cameraRect.top = 0;
	cameraRect.left = 0;
	cameraRect.right = cameraRect.left + 800;
	cameraRect.bottom = cameraRect.top + 600;
}

Camera::~Camera()
{
}

void Camera::Update(D3DXVECTOR2 position)
{
	cameraRect.left = position.x - 400;
	if (cameraRect.left < 0)
		cameraRect.left = 0;
	
}

void Camera::Update(D3DXVECTOR2 position, QuadTree *quadTree)
{
	if (cameraRect.right < quadTree->rect.right)
	{
		if (position.x > cameraRect.right/3)
		{
			cameraRect.left = position.x - (cameraRect.right - cameraRect.left)/3;
		}
	}
	cameraRect.left = position.x - 400;
	if (cameraRect.left < 0)
		cameraRect.left = 0;

}

D3DXMATRIX Camera::GetMatrix()
{
	D3DXMATRIX matrixTransform;
	

	//D3DXMatrixIdentity(&matrixTransform);
	//D3DXMatrixRotationZ(&matrixTransform, D3DXToRadian(90.0f));
	//D3DXMatrixPerspectiveFovLH(&matrixTransform, D3DX_PI/4, 500/500, 1, 50);
	
	D3DXMatrixAffineTransformation2D(&matrixTransform, 1.0f, NULL, 0.0f, &D3DXVECTOR2(-cameraRect.left, -cameraRect.top));
	//D3DXMatrixTranslation(&matrixTransform, -cameraRect.left, -cameraRect.right, 1);
	return matrixTransform;
}